package com.ruoyi.xyq.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.xyq.domain.VTServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xyq.domain.ServiceDetails;
import com.ruoyi.xyq.service.IServiceDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务详情Controller
 * 
 * @author xueyongqi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/details")
public class ServiceDetailsController extends BaseController
{
    @Autowired
    private IServiceDetailsService serviceDetailsService;

    /**
     * 查询服务详情列表
     */
    @RequiresPermissions("xyq:details:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceDetails serviceDetails)
    {
        startPage();
        List<ServiceDetails> list = serviceDetailsService.selectServiceDetailsList(serviceDetails);
        return getDataTable(list);
    }

    /**
     * 查询服务详情列表只返回value/text
     */
    @RequiresPermissions("xyq:details:list")
    @GetMapping("/listServicesWWC")
    public TableDataInfo listServicesWWC(ServiceDetails serviceDetails)
    {
        startPage();
        List<ServiceDetails> list = serviceDetailsService.selectServiceDetailsList(serviceDetails);
        List<VTServices> vtServices = new ArrayList<>();
        for (ServiceDetails details : list) {
            VTServices vtService = new VTServices();
            vtService.setValue(details.getId());
            vtService.setText(details.getName());
            vtService.setIntroduction(details.getIntroduction());
            vtService.setoPrice(details.getOriginalPrice());
            vtService.setpPrice(details.getPresentPrice());
            vtServices.add(vtService);
        }

        return getDataTable(vtServices);
    }

    /**
     * 根据多个id查询多个服务
     */
    @RequiresPermissions("xyq:details:list")
    @PostMapping("/listwwc")
    public R<?> listwwc(@RequestBody ServiceDetails serviceDetail)
    {
        List<ServiceDetails> serviceDetails = serviceDetailsService.selectServiceDetailsByIds(serviceDetail.getIds());
        return R.ok(serviceDetails);
    }

    /**
     * 导出服务详情列表
     */
    @RequiresPermissions("xyq:details:export")
    @Log(title = "服务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceDetails serviceDetails)
    {
        List<ServiceDetails> list = serviceDetailsService.selectServiceDetailsList(serviceDetails);
        ExcelUtil<ServiceDetails> util = new ExcelUtil<ServiceDetails>(ServiceDetails.class);
        util.exportExcel(response, list, "服务详情数据");
    }

    /**
     * 获取服务详情详细信息
     */
    @RequiresPermissions("xyq:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceDetailsService.selectServiceDetailsById(id));
    }

    /**
     * 新增服务详情
     */
    @RequiresPermissions("xyq:details:add")
    @Log(title = "服务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceDetails serviceDetails)
    {
        return toAjax(serviceDetailsService.insertServiceDetails(serviceDetails));
    }

    /**
     * 修改服务详情
     */
    @RequiresPermissions("xyq:details:edit")
    @Log(title = "服务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceDetails serviceDetails)
    {
        return toAjax(serviceDetailsService.updateServiceDetails(serviceDetails));
    }

    /**
     * 删除服务详情
     */
    @RequiresPermissions("xyq:details:remove")
    @Log(title = "服务详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceDetailsService.deleteServiceDetailsByIds(ids));
    }
}
